package com.dixunzh.dianlailai.core.Controllers;


import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.dixunzh.dianlailai.core.Services.WxMpService;


@RestController
@RequestMapping("api/wechatapp")
public class WXAppController {
	
	
	@Autowired
	private WxMpService wxMpService;
	
	@GetMapping("/msg")
	public String msg(String signature,String timestamp,String nonce,String echostr) {
		
		if(wxMpService.msgChk(signature, timestamp, nonce))
			return echostr;
		else
			return null;
	}
	@PostMapping("/msg")
	public String msg(HttpServletRequest request,@RequestBody String testEntity) {
		System.out.println(testEntity);
		Map<String,String> resdata=wxMpService.resMsg(testEntity);
		String data = wxMpService.sendMsg(resdata);
		if(data!=null)
			return data;
		else		
			return "success";
	}
	

}

